﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BitworkStudios.WikiParse.Core.Contracts;
using BitworkStudios.WikiParse.Core.Extensions;
using BitworkStudios.WikiParse.Core.Models;

namespace BitworkStudios.WikiParse.Engine
{
    public class Parser : IParser
    {
        public UploadedFileInformation ProcessFile(Stream file)
        {
            var uploadedFileInformation = new UploadedFileInformation();

            try
            {
                uploadedFileInformation.Size = file.Length;
                uploadedFileInformation.SourceText = file.ToString(Encoding.UTF8);
                uploadedFileInformation.CharacterCount = uploadedFileInformation.SourceText.Length;
                uploadedFileInformation.IsValid = true;
            }
            catch (Exception)
            {
                uploadedFileInformation.IsValid = false;
            }

            return uploadedFileInformation;
        }
    }
}
